<?php
/**
 * Created by PhpStorm.
 * User: dev
 * Date: 29/9/14
 * Time: 11:30 AM
 */

class Location {

    public function __construct() {
        parent::__construct();
    }


    public static function get() {
        $cookie = Cookie::get('location_cookie');
       
        if(!empty($cookie)){

            if(Cache::get("locations_id_".$cookie)){
                $loc = Cache::get("locations_id_".$cookie);
            }else{
                $loc = DB::table('locations')->select('name')->where_id($cookie)->first();
            }

            if($loc){
                return $loc->name;
            }else{
                return Settings::get('en','default_location');
            }

        }else{
            return Settings::get('en','default_location');
        }
    }

    public static function set($lid){
        if(!empty($lid)){
            if($lid){
                Cookie::forever('location_cookie', $lid);
            }
        }
    }

    public static function clear(){
        $lid = Cookie::get('location_cookie');
        if(!empty($lid)){
            if($lid){
                Cookie::forget('location_cookie');
            }
        }
        return true;
    }



} 